<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function handleData(arr, flag = true) {
            let sum = 0
            for (let i = 0; i < arr.length; i++) {
                sum = sum + arr[i]

            }
            if (flag) {
                return `该数组的和是${sum}`
            }
            else {
                let average = sum / arr.length
                return `该数组的平均值是${average}`
            }
        }
        let arr = []
        while (true) {
            let number = +prompt(`请输入数据按enter键结束`)
            if (!Boolean(number)) {
                break
            }
            arr.push(number)
        }
        let re
        let num = prompt(`按任意键求和按enter求平均值`)
        if (Boolean(num)) {
            re = handleData(arr, num)
            document.write(re)
        }
        else {
            re = handleData(arr, num)
            document.write(re)
        }

    </script>
</body>

</html>